package jedis;

import com.alibaba.fastjson.JSON;
import entity.Goods;
import redis.clients.jedis.Jedis;

import java.util.ArrayList;
import java.util.List;

public class cacheGoods {
    public void cache() {
        Jedis jedis = new Jedis("8.130.9.11");
        try {
            jedis.select(3);
            List<Goods> goodsList = new ArrayList<>();
            goodsList.add(new Goods(888, "红富士", "", 10f));
            goodsList.add(new Goods(889, "黄元帅", "", 9f));
            goodsList.add(new Goods(890, "橙子", "", 8f));
            for (Goods goods : goodsList){
                String json = JSON.toJSONString(goods);
                System.out.println(json);
                String key = "good:"+goods.getId();
                jedis.set(key,json);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        jedis.close();
        }

    }
    public static void main(String[] args) {
        cacheGoods cachegoods = new cacheGoods();
        cachegoods.cache();
    }
}
